package 每日一题;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 会玩的洋洋
 * https://leetcode-cn.com/problems/lucky-numbers-in-a-matrix/
 */
public class _1380_矩阵中的幸运数 {
    int N = 55;
    int[] row = new int[N], col = new int[N];
    /**
     * 预处理
     * 记录每一行的最小值 和 每一列的最大值
     * @param matrix 目标矩阵
     * @return List<Integer>条件元素
     */
    public List<Integer> luckyNumbers (int[][] matrix) {
        int n = matrix.length;
        int m = matrix[0].length;
        List<Integer> ans = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            row[i] = 100001;
            for (int j = 0; j < m; j++) {
                row[i] = Math.min(row[i], matrix[i][j]);
                col[j] = Math.max(col[j], matrix[i][j]);
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (row[i] == matrix[i][j] && col[j] == matrix[i][j]) {
                    ans.add(matrix[i][j]);
                }
            }
        }
        return ans;
    }
}
